<?php

namespace App\Http\Middleware;

use Closure;

class LoginMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

       //检测用户是否登陆
        if(session('user')){
            //如果登陆成功则把请求传递给下一层处理(控制器层)
            return $next($request);
        }else{
            //如果没有登陆成功则重定向到登陆页面
            return redirect('/login');
        }
       
    }
}
